﻿package mortal.game.view.task
{
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.GCatogeryList.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.data.*;
    import mortal.game.view.task.view.*;
    import mortal.game.view.task.view.render.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;

    public class TaskModule extends BaseWindow
    {
        private var _list:GCatogeryList;
        private var _bg:GImageBitmap;
        private var _tab:GTabarNew;
        private var _desc:TaskItemDesc;
        public static const taskTabData:Array = [{label:Language.getString(20121), name:"1"}, {label:Language.getString(20122), name:"2"}];

        public function TaskModule()
        {
            this.setSize(589, 425);
            this.title = Language.getString(20120);
            this.titleHeight = 60;
            return;
        }// end function

        public function expand(param1:int = 0) : void
        {
            var nextFrameToExpand:Function;
            var index:* = param1;
            nextFrameToExpand = function () : void
            {
                _list.expandItem(index);
                return;
            }// end function
            ;
            setTimeout(nextFrameToExpand, 100);
            return;
        }// end function

        public function resetList() : void
        {
            DisplayUtil.removeMe(this._list);
            this._list = UICompomentPool.getUICompoment(GCatogeryList);
            this._list.setListSize(184, 354);
            this._list.x = 13;
            this._list.y = 66;
            this._list.tileList.direction = GBoxDirection.VERTICAL;
            this._list.tileList.columnWidth = 172;
            this._list.tileList.columnCount = 1;
            this._list.headGap = 0;
            this.addChild(this._list);
            return;
        }// end function

        public function initHeads(param1:Array) : void
        {
            this._list.createHeads(CatogeryListHead, param1, 170, 22);
            this._list.setCellRender(0, TaskItemCellrender, true);
            this._list.setCellHeight(0, 21, true);
            this._list.setListItemHeight(22);
            return;
        }// end function

        public function setDataProvider(param1:int, param2:DataProvider) : void
        {
            this._list.setDataProvider(param1, param2);
            return;
        }// end function

        public function updateDesc(param1:TaskInfo) : void
        {
            if (param1 == null)
            {
                DisplayUtil.removeMe(this._desc);
            }
            else
            {
                this._desc.taskInfo = param1;
                if (this._desc.parent == null)
                {
                    this.addChild(this._desc);
                }
            }
            return;
        }// end function

        public function getCurDescInfo() : TaskInfo
        {
            if (this._desc == null)
            {
                return null;
            }
            return this._desc.taskInfo;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tab = UIFactory.gTabBarNew(2, 31, taskTabData, 589, 425, 64, 26, this, this.tabbBarChangeHandler, "TabButtonNew");
            pushUIToDisposeVec(UIFactory.bg(8, 58, 189, 364, this, ImagesConst.PanelBg));
            this._bg = UIFactory.gImageBitmap("", 200, 56, this);
            LoaderHelp.setBitmapdata(ImagesConst.TaskPanelBg + ".swf", this._bg);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 15;
            _loc_1.bold = true;
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20261), this._bg.x + 160, this._bg.y + 2, 200, 22, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20262), this._bg.x + 160, this._bg.y + 101, 200, 22, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20263), this._bg.x + 160, this._bg.y + 197, 200, 22, this, _loc_1));
            this._list = UICompomentPool.getUICompoment(GCatogeryList);
            this._list.setListSize(190, 362);
            this._list.x = 8;
            this._list.y = this._bg.y + 1;
            this._list.tileList.direction = GBoxDirection.VERTICAL;
            this._list.tileList.columnWidth = 180;
            this._list.tileList.columnCount = 1;
            this._list.headGap = 0;
            this.addChild(this._list);
            this._desc = UICompomentPool.getUICompoment(TaskItemDesc);
            this._desc.x = this._bg.x + 15;
            this._desc.y = this._bg.y + 27;
            this.addChild(this._desc);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            setTimeout(this.nextFrameWhenShowed, 100);
            return;
        }// end function

        private function nextFrameWhenShowed() : void
        {
            this.tabbBarChangeHandler(null);
            return;
        }// end function

        public function get selectedIndex() : int
        {
            return this._tab.selectedIndex;
        }// end function

        public function set selectedIndex(param1:int) : void
        {
            this._tab.selectedIndex = param1;
            this.tabbBarChangeHandler(null);
            return;
        }// end function

        private function tabbBarChangeHandler(event:Event) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskModuleTabChange));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._list.dispose(param1);
            this._list = null;
            this._tab.dispose(param1);
            this._tab = null;
            this._desc.dispose(param1);
            this._desc = null;
            return;
        }// end function

    }
}
